﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using WJP.Serialization.Mobile;

namespace WJP.ManagedProperty
{
    /// <summary>
    /// 托管属性对象
    /// <para>从此类继承的子类，可以以托管属性的方式声明自己的所有属性。同时，其它的类型可以为其在扩展编译期属性，也可以在运行时动态扩展属性</para>
    /// </summary>
    [CompiledPropertyDeclarer]
    [System.Diagnostics.DebuggerDisplay("{DebuggerDisplay}")]
    [MobileNonSerialized]
    [Serializable]
    public abstract class ManagedPropertyObject : IManagedPropertyObject, INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;

        protected virtual void OnPropertyChanged(string propertyName)
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }

        /// <summary>编译期属性以数组方式存储，使得检索速度是 O(1)</summary>
        [NonSerialized]
        private ManagedPropertyField[] _compiledFields;

        /// <summary>由于运行时属性不会很多，所以使用 Dictionary 类来进行更快速的检索。</summary>
        [NonSerialized]
        private Dictionary<IManagedProperty, ManagedPropertyField> _runtimeFields;

        protected ManagedPropertyObject()
        {
            InitFields();
        }

        private void InitFields()
        {

        }

        /// <summary>
        /// 通过编译期属性来初始化字段数组
        /// </summary>
        /// <param name="compiledPropertyList"></param>
        private void InitFields(ManagedPropertyList compiledPropertyList)
        {
            List<ManagedPropertyField> fields = new List<ManagedPropertyField>();
            compiledPropertyList.GetAll().ForEach(property =>
            {
                ManagedPropertyField field = new ManagedPropertyField();
                field.ResetToProperty(property);
                fields.Add(field);
            });
            _compiledFields = fields.ToArray();
        }

        public object GetProperty(IManagedProperty property)
        {
            throw new NotImplementedException();
        }

        public TPropertyType GetProperty<TPropertyType>(ManagedProperty<TPropertyType> property)
        {
            throw new NotImplementedException();
        }

        public void LoadProperty(IManagedProperty property, object value)
        {
            throw new NotImplementedException();
        }

        public void ResetProperty(IManagedProperty property)
        {
            throw new NotImplementedException();
        }

        public object SetProperty(IManagedProperty property, object value)
        {
            throw new NotImplementedException();
        }

    }
}
